import { createWebHashHistory, createWebHistory, createMemoryHistory } from 'vue-router'
import { router as routerConfig } from '../router'
import { routerhistory, template } from '@/config'

routerConfig.forEach((item) => {
  item.component = () => import(`../pages/${item.page}.vue`)
})

let history = (key, base) => {
  switch (key) {
    case 'createWebHashHistory':
      return createWebHashHistory(base)
    case 'createMemoryHistory':
      return createMemoryHistory(base)
    default:
      return createWebHistory(base)
  }
}

const router = (base) => {
  base = base || template
  return {
    history: history(routerhistory, base),
    routes: routerConfig,
  }
}
// 全局前置守卫
export function beforeEach(to, from, next) {
  next()
}
// 全局后置钩子
export function afterEach(to, from) {}
// 全局解析守卫
export function beforeResolve(to) {}

export default router
